
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
  
  <!-- Licensed under the Apache 2.0 License -->
  <link rel="stylesheet" type="text/css" href="../../../../_static/fonts/open-sans/stylesheet.css" />
  <!-- Licensed under the SIL Open Font License -->
  <link rel="stylesheet" type="text/css" href="../../../../_static/fonts/source-serif-pro/source-serif-pro.css" />
  <link rel="stylesheet" type="text/css" href="../../../../_static/css/bootstrap.min.css" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
    <title>jmetal.algorithm.multiobjective.nsgaiii &#8212; jMetalPy 1.5.3 documentation</title>
    <link rel="stylesheet" href="../../../../_static/guzzle.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../../../_static/custom.css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../../_static/language_data.js"></script>
    <script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
    <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["$", "$"], ["\\(", "\\)"]], "processEscapes": true, "ignoreClass": "document", "processClass": "math|output_area"}})</script>
    <link rel="author" title="About these documents" href="../../../../about.html" />
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
  
   

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">jMetalPy 1.5.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" accesskey="U">Module code</a> &#187;</li> 
      </ul>
    </div>
    <div class="container-wrapper">

      <div id="mobile-toggle">
        <a href="#"><span class="glyphicon glyphicon-align-justify" aria-hidden="true"></span></a>
      </div>
  <div id="left-column">
    <div class="sphinxsidebar"><a href="
    ../../../../index.html" class="text-logo">
    <img src="_static/jmetalpy.png" class="img-fluid" alt="jMetalPy 1.5.3 documentation">
    <br>
</a>

<div class="sidebar-block">
  <div class="sidebar-wrapper">
    Python version of the jMetal framework
  </div>
</div>
<div class="sidebar-block">
  <div class="sidebar-wrapper">
    <h2>Table Of Contents</h2>
  </div>
  <div class="sidebar-toc">
    
    
      <ul>
<li class="toctree-l1"><a class="reference internal" href="../../../../tutorials.html">Getting started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../multiobjective.algorithms.html">Multi-objective algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../singleobjective.algorithms.html">Single-objective algorithms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../operators.html">Operators</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../problems.html">Problems</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../contributing.html">Contributing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../../about.html">About</a></li>
</ul>

    
  </div>
</div>
<div class="sidebar-block">
  <div class="sidebar-wrapper">
    <div id="main-search">
      <form class="form-inline" action="../../../../search.html" method="GET" role="form">
        <div class="input-group">
          <input name="q" type="text" class="form-control" placeholder="Search...">
        </div>
        <input type="hidden" name="check_keywords" value="yes" />
        <input type="hidden" name="area" value="default" />
      </form>
    </div>
  </div>
</div>
      
    </div>
  </div>
        <div id="right-column">
          
          <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
              <li class="breadcrumb-item"><a href="../../../../index.html">Docs</a></li>
              
              <li class="breadcrumb-item"><a href="../../../index.html">Module code</a></li>
              
              <li class="breadcrumb-item">jmetal.algorithm.multiobjective.nsgaiii</li>
            </ol>
          </nav>
          
          <div class="document clearer body">
            
  <h1>Source code for jmetal.algorithm.multiobjective.nsgaiii</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">abc</span> <span class="k">import</span> <span class="n">abstractmethod</span><span class="p">,</span> <span class="n">ABC</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="k">import</span> <span class="n">TypeVar</span><span class="p">,</span> <span class="n">List</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">numpy.linalg</span> <span class="k">import</span> <span class="n">LinAlgError</span>
<span class="kn">from</span> <span class="nn">scipy</span> <span class="k">import</span> <span class="n">special</span>

<span class="kn">from</span> <span class="nn">jmetal.algorithm.multiobjective.nsgaii</span> <span class="k">import</span> <span class="n">NSGAII</span>
<span class="kn">from</span> <span class="nn">jmetal.config</span> <span class="k">import</span> <span class="n">store</span>
<span class="kn">from</span> <span class="nn">jmetal.core.operator</span> <span class="k">import</span> <span class="n">Mutation</span><span class="p">,</span> <span class="n">Crossover</span><span class="p">,</span> <span class="n">Selection</span>
<span class="kn">from</span> <span class="nn">jmetal.core.problem</span> <span class="k">import</span> <span class="n">Problem</span>
<span class="kn">from</span> <span class="nn">jmetal.operator</span> <span class="k">import</span> <span class="n">BinaryTournamentSelection</span>
<span class="kn">from</span> <span class="nn">jmetal.util.comparator</span> <span class="k">import</span> <span class="n">Comparator</span><span class="p">,</span> <span class="n">MultiComparator</span>
<span class="kn">from</span> <span class="nn">jmetal.util.density_estimator</span> <span class="k">import</span> <span class="n">CrowdingDistance</span>
<span class="kn">from</span> <span class="nn">jmetal.util.evaluator</span> <span class="k">import</span> <span class="n">Evaluator</span>
<span class="kn">from</span> <span class="nn">jmetal.util.generator</span> <span class="k">import</span> <span class="n">Generator</span>
<span class="kn">from</span> <span class="nn">jmetal.util.ranking</span> <span class="k">import</span> <span class="n">FastNonDominatedRanking</span>
<span class="kn">from</span> <span class="nn">jmetal.util.termination_criterion</span> <span class="k">import</span> <span class="n">TerminationCriterion</span>

<span class="n">S</span> <span class="o">=</span> <span class="n">TypeVar</span><span class="p">(</span><span class="s1">&#39;S&#39;</span><span class="p">)</span>
<span class="n">R</span> <span class="o">=</span> <span class="n">TypeVar</span><span class="p">(</span><span class="s1">&#39;R&#39;</span><span class="p">)</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">.. module:: NSGA-III</span>
<span class="sd">   :platform: Unix, Windows</span>
<span class="sd">   :synopsis: NSGA-III (Non-dominance Sorting Genetic Algorithm III) implementation.</span>

<span class="sd">.. moduleauthor:: Antonio Benítez-Hidalgo &lt;antonio.b@uma.es&gt;, Julian Blank &lt;blankjul@egr.msu.edu&gt;</span>
<span class="sd">&quot;&quot;&quot;</span>


<span class="k">class</span> <span class="nc">ReferenceDirectionFactory</span><span class="p">(</span><span class="n">ABC</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n_dim</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">scaling</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">n_dim</span> <span class="o">=</span> <span class="n">n_dim</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">scaling</span> <span class="o">=</span> <span class="n">scaling</span>

    <span class="k">def</span> <span class="nf">compute</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">n_dim</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mf">1.0</span><span class="p">]])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">ref_dirs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_compute</span><span class="p">()</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">scaling</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">ref_dirs</span> <span class="o">=</span> <span class="n">ref_dirs</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">scaling</span> <span class="o">+</span> <span class="p">((</span><span class="mi">1</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">scaling</span><span class="p">)</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">n_dim</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">ref_dirs</span>

    <span class="nd">@abstractmethod</span>
    <span class="k">def</span> <span class="nf">_compute</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">pass</span>


<span class="k">class</span> <span class="nc">UniformReferenceDirectionFactory</span><span class="p">(</span><span class="n">ReferenceDirectionFactory</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n_dim</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">scaling</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">n_points</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">n_partitions</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">n_dim</span><span class="p">,</span> <span class="n">scaling</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">n_points</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">n_partitions</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_partition_closest_to_points</span><span class="p">(</span><span class="n">n_points</span><span class="p">,</span> <span class="n">n_dim</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">n_partitions</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;Either provide number of partitions or number of points.&quot;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">n_partitions</span> <span class="o">=</span> <span class="n">n_partitions</span>

    <span class="k">def</span> <span class="nf">_compute</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">uniform_reference_directions</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">n_partitions</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">n_dim</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">uniform_reference_directions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n_partitions</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">n_dim</span><span class="p">:</span> <span class="nb">int</span><span class="p">):</span>
        <span class="n">ref_dirs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">ref_dir</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">full</span><span class="p">(</span><span class="n">n_dim</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__uniform_reference_directions</span><span class="p">(</span><span class="n">ref_dirs</span><span class="p">,</span> <span class="n">ref_dir</span><span class="p">,</span> <span class="n">n_partitions</span><span class="p">,</span> <span class="n">n_partitions</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">ref_dirs</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">__uniform_reference_directions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ref_dirs</span><span class="p">,</span> <span class="n">ref_dir</span><span class="p">,</span> <span class="n">n_partitions</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">beta</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">depth</span><span class="p">:</span> <span class="nb">int</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">depth</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">ref_dir</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">ref_dir</span><span class="p">[</span><span class="n">depth</span><span class="p">]</span> <span class="o">=</span> <span class="n">beta</span> <span class="o">/</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">*</span> <span class="n">n_partitions</span><span class="p">)</span>
            <span class="n">ref_dirs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ref_dir</span><span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="p">:])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">beta</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
                <span class="n">ref_dir</span><span class="p">[</span><span class="n">depth</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="o">*</span> <span class="n">i</span> <span class="o">/</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">*</span> <span class="n">n_partitions</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__uniform_reference_directions</span><span class="p">(</span><span class="n">ref_dirs</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">ref_dir</span><span class="p">),</span> <span class="n">n_partitions</span><span class="p">,</span> <span class="n">beta</span> <span class="o">-</span> <span class="n">i</span><span class="p">,</span>
                                                    <span class="n">depth</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">get_partition_closest_to_points</span><span class="p">(</span><span class="n">n_points</span><span class="p">,</span> <span class="n">n_dim</span><span class="p">):</span>
        <span class="c1"># in this case the do method will always return one values anyway</span>
        <span class="k">if</span> <span class="n">n_dim</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">return</span> <span class="mi">0</span>

        <span class="n">n_partitions</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="n">_n_points</span> <span class="o">=</span> <span class="n">UniformReferenceDirectionFactory</span><span class="o">.</span><span class="n">get_n_points</span><span class="p">(</span><span class="n">n_partitions</span><span class="p">,</span> <span class="n">n_dim</span><span class="p">)</span>
        <span class="k">while</span> <span class="n">_n_points</span> <span class="o">&lt;=</span> <span class="n">n_points</span><span class="p">:</span>
            <span class="n">n_partitions</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">_n_points</span> <span class="o">=</span> <span class="n">UniformReferenceDirectionFactory</span><span class="o">.</span><span class="n">get_n_points</span><span class="p">(</span><span class="n">n_partitions</span><span class="p">,</span> <span class="n">n_dim</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">n_partitions</span> <span class="o">-</span> <span class="mi">1</span>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">get_n_points</span><span class="p">(</span><span class="n">n_partitions</span><span class="p">,</span> <span class="n">n_dim</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">special</span><span class="o">.</span><span class="n">binom</span><span class="p">(</span><span class="n">n_dim</span> <span class="o">+</span> <span class="n">n_partitions</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n_partitions</span><span class="p">))</span>


<span class="k">def</span> <span class="nf">get_extreme_points</span><span class="p">(</span><span class="n">F</span><span class="p">,</span> <span class="n">n_objs</span><span class="p">,</span> <span class="n">ideal_point</span><span class="p">,</span> <span class="n">extreme_points</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Calculate the Achievement Scalarization Function which is used for the extreme point decomposition. &quot;&quot;&quot;</span>
    <span class="n">asf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="n">n_objs</span><span class="p">)</span>
    <span class="n">asf</span><span class="p">[</span><span class="n">asf</span> <span class="o">==</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1e6</span>

    <span class="c1"># add the old extreme points to never loose them for normalization</span>
    <span class="n">_F</span> <span class="o">=</span> <span class="n">F</span>
    <span class="k">if</span> <span class="n">extreme_points</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">_F</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">([</span><span class="n">extreme_points</span><span class="p">,</span> <span class="n">_F</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

    <span class="c1"># use __F because we substitute small values to be 0</span>
    <span class="n">__F</span> <span class="o">=</span> <span class="n">_F</span> <span class="o">-</span> <span class="n">ideal_point</span>
    <span class="n">__F</span><span class="p">[</span><span class="n">__F</span> <span class="o">&lt;</span> <span class="mf">1e-3</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>

    <span class="c1"># update the extreme points for the normalization having the highest asf value each</span>
    <span class="n">F_asf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">__F</span> <span class="o">*</span> <span class="n">asf</span><span class="p">[:,</span> <span class="kc">None</span><span class="p">,</span> <span class="p">:],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
    <span class="n">idx</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="n">F_asf</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">extreme_points</span> <span class="o">=</span> <span class="n">_F</span><span class="p">[</span><span class="n">idx</span><span class="p">,</span> <span class="p">:]</span>

    <span class="k">return</span> <span class="n">extreme_points</span>


<span class="k">def</span> <span class="nf">get_nadir_point</span><span class="p">(</span><span class="n">extreme_points</span><span class="p">,</span> <span class="n">ideal_point</span><span class="p">,</span> <span class="n">worst_point</span><span class="p">,</span> <span class="n">worst_of_front</span><span class="p">,</span> <span class="n">worst_of_population</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Calculate the axis intersects for a set of individuals and its extremes (construct hyperplane). &quot;&quot;&quot;</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="c1"># find the intercepts using gaussian elimination</span>
        <span class="n">M</span> <span class="o">=</span> <span class="n">extreme_points</span> <span class="o">-</span> <span class="n">ideal_point</span>
        <span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">extreme_points</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="n">plane</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">solve</span><span class="p">(</span><span class="n">M</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
        <span class="n">intercepts</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">/</span> <span class="n">plane</span>

        <span class="n">nadir_point</span> <span class="o">=</span> <span class="n">ideal_point</span> <span class="o">+</span> <span class="n">intercepts</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">M</span><span class="p">,</span> <span class="n">plane</span><span class="p">),</span> <span class="n">b</span><span class="p">)</span> <span class="ow">or</span> <span class="n">np</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="n">intercepts</span> <span class="o">&lt;=</span> <span class="mf">1e-6</span><span class="p">)</span> <span class="ow">or</span> <span class="n">np</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="n">nadir_point</span> <span class="o">&gt;</span> <span class="n">worst_point</span><span class="p">):</span>
            <span class="k">raise</span> <span class="n">LinAlgError</span><span class="p">()</span>
    <span class="k">except</span> <span class="n">LinAlgError</span><span class="p">:</span>
        <span class="n">nadir_point</span> <span class="o">=</span> <span class="n">worst_of_front</span>

    <span class="n">b</span> <span class="o">=</span> <span class="n">nadir_point</span> <span class="o">-</span> <span class="n">ideal_point</span> <span class="o">&lt;=</span> <span class="mf">1e-6</span>
    <span class="n">nadir_point</span><span class="p">[</span><span class="n">b</span><span class="p">]</span> <span class="o">=</span> <span class="n">worst_of_population</span><span class="p">[</span><span class="n">b</span><span class="p">]</span>

    <span class="k">return</span> <span class="n">nadir_point</span>


<span class="k">def</span> <span class="nf">niching</span><span class="p">(</span><span class="n">pop</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">S</span><span class="p">],</span> <span class="n">n_remaining</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">niche_count</span><span class="p">,</span> <span class="n">niche_of_individuals</span><span class="p">,</span> <span class="n">dist_to_niche</span><span class="p">):</span>
    <span class="n">survivors</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="c1"># boolean array of elements that are considered for each iteration</span>
    <span class="n">mask</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">full</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">pop</span><span class="p">),</span> <span class="kc">True</span><span class="p">)</span>

    <span class="k">while</span> <span class="nb">len</span><span class="p">(</span><span class="n">survivors</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">n_remaining</span><span class="p">:</span>
        <span class="c1"># number of individuals to select in this iteration</span>
        <span class="n">n_select</span> <span class="o">=</span> <span class="n">n_remaining</span> <span class="o">-</span> <span class="nb">len</span><span class="p">(</span><span class="n">survivors</span><span class="p">)</span>

        <span class="c1"># all niches where new individuals can be assigned to and the corresponding niche count</span>
        <span class="n">next_niches_list</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">unique</span><span class="p">(</span><span class="n">niche_of_individuals</span><span class="p">[</span><span class="n">mask</span><span class="p">])</span>
        <span class="n">next_niche_count</span> <span class="o">=</span> <span class="n">niche_count</span><span class="p">[</span><span class="n">next_niches_list</span><span class="p">]</span>

        <span class="c1"># the minimum niche count</span>
        <span class="n">min_niche_count</span> <span class="o">=</span> <span class="n">next_niche_count</span><span class="o">.</span><span class="n">min</span><span class="p">()</span>

        <span class="c1"># all niches with the minimum niche count (truncate if randomly select more niches than remaining individuals)</span>
        <span class="n">next_niches</span> <span class="o">=</span> <span class="n">next_niches_list</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">next_niche_count</span> <span class="o">==</span> <span class="n">min_niche_count</span><span class="p">)[</span><span class="mi">0</span><span class="p">]]</span>
        <span class="n">next_niches</span> <span class="o">=</span> <span class="n">next_niches</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">permutation</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">next_niches</span><span class="p">))[:</span><span class="n">n_select</span><span class="p">]]</span>

        <span class="k">for</span> <span class="n">next_niche</span> <span class="ow">in</span> <span class="n">next_niches</span><span class="p">:</span>
            <span class="c1"># indices of individuals that are considered and assign to next_niche</span>
            <span class="n">next_ind</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">logical_and</span><span class="p">(</span><span class="n">niche_of_individuals</span> <span class="o">==</span> <span class="n">next_niche</span><span class="p">,</span> <span class="n">mask</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span>

            <span class="c1"># shuffle to break random_search tie (equal perp. dist) or select randomly</span>
            <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">shuffle</span><span class="p">(</span><span class="n">next_ind</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">niche_count</span><span class="p">[</span><span class="n">next_niche</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">next_ind</span> <span class="o">=</span> <span class="n">next_ind</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="n">dist_to_niche</span><span class="p">[</span><span class="n">next_ind</span><span class="p">])]</span>
                <span class="n">is_closest</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c1"># already randomized through shuffling</span>
                <span class="n">next_ind</span> <span class="o">=</span> <span class="n">next_ind</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="n">is_closest</span> <span class="o">=</span> <span class="kc">False</span>

            <span class="c1"># add the selected individual to the survivors</span>
            <span class="n">mask</span><span class="p">[</span><span class="n">next_ind</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="n">pop</span><span class="p">[</span><span class="n">next_ind</span><span class="p">]</span><span class="o">.</span><span class="n">attributes</span><span class="p">[</span><span class="s1">&#39;is_closest&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">is_closest</span>
            <span class="n">survivors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">next_ind</span><span class="p">))</span>

            <span class="c1"># increase the corresponding niche count</span>
            <span class="n">niche_count</span><span class="p">[</span><span class="n">next_niche</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>

    <span class="k">return</span> <span class="n">survivors</span>


<span class="k">def</span> <span class="nf">associate_to_niches</span><span class="p">(</span><span class="n">F</span><span class="p">,</span> <span class="n">niches</span><span class="p">,</span> <span class="n">ideal_point</span><span class="p">,</span> <span class="n">nadir_point</span><span class="p">,</span> <span class="n">utopian_epsilon</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">0.0</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Associate each solution to a reference point. &quot;&quot;&quot;</span>
    <span class="n">utopian_point</span> <span class="o">=</span> <span class="n">ideal_point</span> <span class="o">-</span> <span class="n">utopian_epsilon</span>

    <span class="n">denom</span> <span class="o">=</span> <span class="n">nadir_point</span> <span class="o">-</span> <span class="n">utopian_point</span>
    <span class="n">denom</span><span class="p">[</span><span class="n">denom</span> <span class="o">==</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1e-12</span>

    <span class="c1"># normalize by ideal point and intercepts</span>
    <span class="n">N</span> <span class="o">=</span> <span class="p">(</span><span class="n">F</span> <span class="o">-</span> <span class="n">utopian_point</span><span class="p">)</span> <span class="o">/</span> <span class="n">denom</span>

    <span class="k">def</span> <span class="nf">compute_perpendicular_distance</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="n">ref_dirs</span><span class="p">):</span>
        <span class="n">u</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">tile</span><span class="p">(</span><span class="n">ref_dirs</span><span class="p">,</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">N</span><span class="p">),</span> <span class="mi">1</span><span class="p">))</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">repeat</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">ref_dirs</span><span class="p">),</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

        <span class="n">norm_u</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">u</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

        <span class="n">scalar_proj</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">v</span> <span class="o">*</span> <span class="n">u</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="n">norm_u</span>
        <span class="n">proj</span> <span class="o">=</span> <span class="n">scalar_proj</span><span class="p">[:,</span> <span class="kc">None</span><span class="p">]</span> <span class="o">*</span> <span class="n">u</span> <span class="o">/</span> <span class="n">norm_u</span><span class="p">[:,</span> <span class="kc">None</span><span class="p">]</span>
        <span class="n">val</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">proj</span> <span class="o">-</span> <span class="n">v</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">matrix</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">N</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="n">ref_dirs</span><span class="p">)))</span>

        <span class="k">return</span> <span class="n">matrix</span>

    <span class="n">dist_matrix</span> <span class="o">=</span> <span class="n">compute_perpendicular_distance</span><span class="p">(</span><span class="n">N</span><span class="p">,</span> <span class="n">niches</span><span class="p">)</span>

    <span class="n">niche_of_individuals</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="n">dist_matrix</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">dist_to_niche</span> <span class="o">=</span> <span class="n">dist_matrix</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="n">niche_of_individuals</span><span class="p">]</span>

    <span class="k">return</span> <span class="n">niche_of_individuals</span><span class="p">,</span> <span class="n">dist_to_niche</span>


<span class="k">def</span> <span class="nf">compute_niche_count</span><span class="p">(</span><span class="n">n_niches</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">niche_of_individuals</span><span class="p">):</span>
    <span class="n">niche_count</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">n_niches</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">)</span>
    <span class="n">index</span><span class="p">,</span> <span class="n">count</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">unique</span><span class="p">(</span><span class="n">niche_of_individuals</span><span class="p">,</span> <span class="n">return_counts</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">niche_count</span><span class="p">[</span><span class="n">index</span><span class="p">]</span> <span class="o">=</span> <span class="n">count</span>

    <span class="k">return</span> <span class="n">niche_count</span>


<div class="viewcode-block" id="NSGAIII"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/nsgaiii.html#jmetal.algorithm.multiobjective.nsgaiii.NSGAIII">[docs]</a><span class="k">class</span> <span class="nc">NSGAIII</span><span class="p">(</span><span class="n">NSGAII</span><span class="p">):</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                 <span class="n">reference_directions</span><span class="p">,</span>
                 <span class="n">problem</span><span class="p">:</span> <span class="n">Problem</span><span class="p">,</span>
                 <span class="n">mutation</span><span class="p">:</span> <span class="n">Mutation</span><span class="p">,</span>
                 <span class="n">crossover</span><span class="p">:</span> <span class="n">Crossover</span><span class="p">,</span>
                 <span class="n">population_size</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                 <span class="n">selection</span><span class="p">:</span> <span class="n">Selection</span> <span class="o">=</span> <span class="n">BinaryTournamentSelection</span><span class="p">(</span>
                     <span class="n">MultiComparator</span><span class="p">([</span><span class="n">FastNonDominatedRanking</span><span class="o">.</span><span class="n">get_comparator</span><span class="p">(),</span>
                                      <span class="n">CrowdingDistance</span><span class="o">.</span><span class="n">get_comparator</span><span class="p">()])),</span>
                 <span class="n">termination_criterion</span><span class="p">:</span> <span class="n">TerminationCriterion</span> <span class="o">=</span> <span class="n">store</span><span class="o">.</span><span class="n">default_termination_criteria</span><span class="p">,</span>
                 <span class="n">population_generator</span><span class="p">:</span> <span class="n">Generator</span> <span class="o">=</span> <span class="n">store</span><span class="o">.</span><span class="n">default_generator</span><span class="p">,</span>
                 <span class="n">population_evaluator</span><span class="p">:</span> <span class="n">Evaluator</span> <span class="o">=</span> <span class="n">store</span><span class="o">.</span><span class="n">default_evaluator</span><span class="p">,</span>
                 <span class="n">dominance_comparator</span><span class="p">:</span> <span class="n">Comparator</span> <span class="o">=</span> <span class="n">store</span><span class="o">.</span><span class="n">default_comparator</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">reference_directions</span> <span class="o">=</span> <span class="n">reference_directions</span><span class="o">.</span><span class="n">compute</span><span class="p">()</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">population_size</span><span class="p">:</span>
            <span class="n">population_size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">reference_directions</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">reference_directions</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="n">problem</span><span class="o">.</span><span class="n">number_of_objectives</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;Dimensionality of reference points must be equal to the number of objectives&#39;</span><span class="p">)</span>

        <span class="nb">super</span><span class="p">(</span><span class="n">NSGAIII</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span>
            <span class="n">problem</span><span class="o">=</span><span class="n">problem</span><span class="p">,</span>
            <span class="n">population_size</span><span class="o">=</span><span class="n">population_size</span><span class="p">,</span>
            <span class="n">offspring_population_size</span><span class="o">=</span><span class="n">population_size</span><span class="p">,</span>
            <span class="n">mutation</span><span class="o">=</span><span class="n">mutation</span><span class="p">,</span>
            <span class="n">crossover</span><span class="o">=</span><span class="n">crossover</span><span class="p">,</span>
            <span class="n">selection</span><span class="o">=</span><span class="n">selection</span><span class="p">,</span>
            <span class="n">termination_criterion</span><span class="o">=</span><span class="n">termination_criterion</span><span class="p">,</span>
            <span class="n">population_evaluator</span><span class="o">=</span><span class="n">population_evaluator</span><span class="p">,</span>
            <span class="n">population_generator</span><span class="o">=</span><span class="n">population_generator</span><span class="p">,</span>
            <span class="n">dominance_comparator</span><span class="o">=</span><span class="n">dominance_comparator</span>
        <span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">extreme_points</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ideal_point</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">full</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">problem</span><span class="o">.</span><span class="n">number_of_objectives</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">worst_point</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">full</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">problem</span><span class="o">.</span><span class="n">number_of_objectives</span><span class="p">,</span> <span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">inf</span><span class="p">)</span>

<div class="viewcode-block" id="NSGAIII.replacement"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/nsgaiii.html#jmetal.algorithm.multiobjective.nsgaiii.NSGAIII.replacement">[docs]</a>    <span class="k">def</span> <span class="nf">replacement</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">population</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">S</span><span class="p">],</span> <span class="n">offspring_population</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="n">S</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">S</span><span class="p">]:</span>
        <span class="sd">&quot;&quot;&quot; Implements NSGA-III environmental selection based on reference points as described in:</span>

<span class="sd">        * Deb, K., &amp; Jain, H. (2014). An Evolutionary Many-Objective Optimization</span>
<span class="sd">          Algorithm Using Reference-Point-Based Nondominated Sorting Approach,</span>
<span class="sd">          Part I: Solving Problems With Box Constraints. IEEE Transactions on</span>
<span class="sd">          Evolutionary Computation, 18(4), 577–601. doi:10.1109/TEVC.2013.2281535.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">F</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">s</span><span class="o">.</span><span class="n">objectives</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">population</span><span class="p">])</span>

        <span class="c1"># find or usually update the new ideal point - from feasible solutions</span>
        <span class="c1"># note that we are assuming minimization here!</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ideal_point</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">min</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">ideal_point</span><span class="p">,</span> <span class="n">F</span><span class="p">)),</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">worst_point</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">worst_point</span><span class="p">,</span> <span class="n">F</span><span class="p">)),</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

        <span class="c1"># calculate the fronts of the population</span>
        <span class="n">ranking</span> <span class="o">=</span> <span class="n">FastNonDominatedRanking</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dominance_comparator</span><span class="p">)</span>
        <span class="n">ranking</span><span class="o">.</span><span class="n">compute_ranking</span><span class="p">(</span><span class="n">population</span> <span class="o">+</span> <span class="n">offspring_population</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">population_size</span><span class="p">)</span>

        <span class="n">fronts</span><span class="p">,</span> <span class="n">non_dominated</span> <span class="o">=</span> <span class="n">ranking</span><span class="o">.</span><span class="n">ranked_sublists</span><span class="p">,</span> <span class="n">ranking</span><span class="o">.</span><span class="n">get_subfront</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>

        <span class="c1"># find the extreme points for normalization</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">extreme_points</span> <span class="o">=</span> <span class="n">get_extreme_points</span><span class="p">(</span><span class="n">F</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">s</span><span class="o">.</span><span class="n">objectives</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">non_dominated</span><span class="p">]),</span>
                                                 <span class="n">n_objs</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">problem</span><span class="o">.</span><span class="n">number_of_objectives</span><span class="p">,</span>
                                                 <span class="n">ideal_point</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ideal_point</span><span class="p">,</span>
                                                 <span class="n">extreme_points</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">extreme_points</span><span class="p">)</span>

        <span class="c1"># find the intercepts for normalization and do backup if gaussian elimination fails</span>
        <span class="n">worst_of_population</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">F</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
        <span class="n">worst_of_front</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">s</span><span class="o">.</span><span class="n">objectives</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">non_dominated</span><span class="p">]),</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

        <span class="n">nadir_point</span> <span class="o">=</span> <span class="n">get_nadir_point</span><span class="p">(</span><span class="n">extreme_points</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">extreme_points</span><span class="p">,</span>
                                      <span class="n">ideal_point</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ideal_point</span><span class="p">,</span>
                                      <span class="n">worst_point</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">worst_point</span><span class="p">,</span>
                                      <span class="n">worst_of_population</span><span class="o">=</span><span class="n">worst_of_population</span><span class="p">,</span>
                                      <span class="n">worst_of_front</span><span class="o">=</span><span class="n">worst_of_front</span><span class="p">)</span>

        <span class="c1">#  consider only the population until we come to the splitting front</span>
        <span class="n">pop</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">ranking</span><span class="o">.</span><span class="n">ranked_sublists</span><span class="p">)</span>
        <span class="n">F</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">s</span><span class="o">.</span><span class="n">objectives</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">pop</span><span class="p">])</span>

        <span class="c1"># update the front indices for the current population</span>
        <span class="n">counter</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">fronts</span><span class="p">)):</span>
            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">fronts</span><span class="p">[</span><span class="n">i</span><span class="p">])):</span>
                <span class="n">fronts</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">counter</span>
                <span class="n">counter</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">last_front</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">fronts</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

        <span class="c1"># associate individuals to niches</span>
        <span class="n">niche_of_individuals</span><span class="p">,</span> <span class="n">dist_to_niche</span> <span class="o">=</span> <span class="n">associate_to_niches</span><span class="p">(</span><span class="n">F</span><span class="o">=</span><span class="n">F</span><span class="p">,</span>
                                                                  <span class="n">niches</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">reference_directions</span><span class="p">,</span>
                                                                  <span class="n">ideal_point</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">ideal_point</span><span class="p">,</span>
                                                                  <span class="n">nadir_point</span><span class="o">=</span><span class="n">nadir_point</span><span class="p">)</span>

        <span class="c1"># if we need to select individuals to survive</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">pop</span><span class="p">)</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">population_size</span><span class="p">:</span>
            <span class="c1"># if there is only one front</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">fronts</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                <span class="n">until_last_front</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">)</span>
                <span class="n">niche_count</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">reference_directions</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">int</span><span class="p">)</span>
                <span class="n">n_remaining</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">population_size</span>
            <span class="c1"># if some individuals already survived</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">until_last_front</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">fronts</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
                <span class="n">niche_count</span> <span class="o">=</span> <span class="n">compute_niche_count</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">reference_directions</span><span class="p">),</span>
                                                  <span class="n">niche_of_individuals</span><span class="p">[</span><span class="n">until_last_front</span><span class="p">])</span>
                <span class="n">n_remaining</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">population_size</span> <span class="o">-</span> <span class="nb">len</span><span class="p">(</span><span class="n">until_last_front</span><span class="p">)</span>

            <span class="n">S_idx</span> <span class="o">=</span> <span class="n">niching</span><span class="p">(</span><span class="n">pop</span><span class="o">=</span><span class="n">pop</span><span class="p">[</span><span class="n">last_front</span><span class="p">],</span>
                            <span class="n">n_remaining</span><span class="o">=</span><span class="n">n_remaining</span><span class="p">,</span>
                            <span class="n">niche_count</span><span class="o">=</span><span class="n">niche_count</span><span class="p">,</span>
                            <span class="n">niche_of_individuals</span><span class="o">=</span><span class="n">niche_of_individuals</span><span class="p">[</span><span class="n">last_front</span><span class="p">],</span>
                            <span class="n">dist_to_niche</span><span class="o">=</span><span class="n">dist_to_niche</span><span class="p">[</span><span class="n">last_front</span><span class="p">])</span>

            <span class="n">survivors_idx</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">((</span><span class="n">until_last_front</span><span class="p">,</span> <span class="n">last_front</span><span class="p">[</span><span class="n">S_idx</span><span class="p">]</span><span class="o">.</span><span class="n">tolist</span><span class="p">()))</span>
            <span class="n">pop</span> <span class="o">=</span> <span class="n">pop</span><span class="p">[</span><span class="n">survivors_idx</span><span class="p">]</span>

        <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">pop</span><span class="p">)</span></div>

<div class="viewcode-block" id="NSGAIII.get_result"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/nsgaiii.html#jmetal.algorithm.multiobjective.nsgaiii.NSGAIII.get_result">[docs]</a>    <span class="k">def</span> <span class="nf">get_result</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot; Return only non dominated solutions.&quot;&quot;&quot;</span>
        <span class="n">ranking</span> <span class="o">=</span> <span class="n">FastNonDominatedRanking</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dominance_comparator</span><span class="p">)</span>
        <span class="n">ranking</span><span class="o">.</span><span class="n">compute_ranking</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">solutions</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">population_size</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">ranking</span><span class="o">.</span><span class="n">get_subfront</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span></div>

<div class="viewcode-block" id="NSGAIII.get_name"><a class="viewcode-back" href="../../../../api/algorithm/multiobjective/eas/nsgaiii.html#jmetal.algorithm.multiobjective.nsgaiii.NSGAIII.get_name">[docs]</a>    <span class="k">def</span> <span class="nf">get_name</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
        <span class="k">return</span> <span class="s1">&#39;NSGAIII&#39;</span></div></div>
</pre></div>

          </div>
            
        </div>
        <div class="clearfix"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">jMetalPy 1.5.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li> 
      </ul>
    </div>
<script type="text/javascript">
  $("#mobile-toggle a").click(function () {
    $("#left-column").toggle();
  });
</script>
<script type="text/javascript" src="../../../../_static/js/bootstrap.js"></script>
  <div class="footer">
    &copy; Copyright 2019, Antonio Benítez-Hidalgo. Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
  </div>
  </body>
</html>